package com.zrrd.mybatis_02.mapper;

import com.zrrd.mybatis_02.entity.Classes;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title ClassesMapper
 * @description
 * @create 2024/10/17
 */
public interface ClassesMapper {
    /**
     * 查询班级列表，包括每个班级里的学生
     * @return
     */
    @Select("SELECT * FROM classes")
    @Results({
            @Result(column ="id",property = "id"),
            @Result(column ="name",property = "name"),
            @Result(column ="id", //根据查询出来的班级表里的班级id去查Student表
                    property = "students",  //被包含对象的变量名
                    javaType = List.class,  //被包含的对象的实际数据类型
                    //many、@Many 是一对多的固定写法
                    many = @Many(select = "com.zrrd.mybatis_02.mapper.StudentMapper.selectByCid")
            )
    })
    List<Classes> selectAll();
}
